<?php

namespace iflow\swoole\implement\Server\Tcp;

use iflow\Container\Container;
use iflow\swoole\abstracts\ServicesAbstract;
use iflow\swoole\implement\Server\Tcp\Events\Event;

class Service extends ServicesAbstract {

    protected array $events = [
        'start' => 'onStart',
        'receive' => 'onReceive',
        'packet' => 'onPacket',
        'connect' => 'onConnect',
        'close' => 'onClose',
        'pipeMessage' => 'onPipeMessage'
    ];

    protected string $defaultEventClass = Event::class;

    public function start() {
        parent::start(); // TODO: Change the autogenerated stub

        $this -> registerSwServiceEvent(
            Container::getInstance() -> make($this->getEventClass(), [ $this ])
        ) -> printStartContextToConsole('tcp');

        $this->SwService -> start();
    }


    public function reload(): bool {
        $this->servicesCommand -> Console -> outWrite('reload services Success');
        return $this->SwService -> reload(); // TODO: Change the autogenerated stub
    }

    protected function setServerParams(): ServicesAbstract {
        parent::setServerParams(); // TODO: Change the autogenerated stub

        $this->_params[] = $this->config -> get('listener@mode', SWOOLE_PROCESS);
        $this->_params[] = $this->config -> get('listener@sockType', SWOOLE_SOCK_TCP);

        return $this;
    }

}